package com.itzhoun.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @author 周楠
 * @Date 2022/09/12/下午 1:23
 */
@Configuration
public class FanoutRabbitConfig {

    public final static String FANOUT_QUEUE_A ="fanout.A";

    public final static String FANOUT_QUEUE_B ="fanout.B";

    public final static String FANOUT_QUEUE_C ="fanout.C";


    /**
     *  创建三个队列 ：fanout.A   fanout.B  fanout.C
     *  将三个队列都绑定在交换机 fanoutExchange 上
     *  因为是扇型交换机, 路由键无需配置,配置也不起作用
     *  扇型交换机主要是实现广播作用
     */
    @Bean
    public Queue queueA(){
        return new Queue(FanoutRabbitConfig.FANOUT_QUEUE_A);
    }

    @Bean
    public Queue queueB(){
        return new Queue(FanoutRabbitConfig.FANOUT_QUEUE_B);
    }

    @Bean
    public Queue queueC(){
        return new Queue(FanoutRabbitConfig.FANOUT_QUEUE_C);
    }

    @Bean
    FanoutExchange fanoutExchange(){
        return new FanoutExchange("fanoutExchange");
    }

    /**
     * 队列绑定交换机
     * @return
     */
    @Bean
    Binding bindingExchangeA() {
        return BindingBuilder.bind(queueA()).to(fanoutExchange());
    }

    @Bean
    Binding bindingExchangeB() {
        return BindingBuilder.bind(queueB()).to(fanoutExchange());
    }

    @Bean
    Binding bindingExchangeC() {
        return BindingBuilder.bind(queueC()).to(fanoutExchange());
    }
}
